package NetWork;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * ClassName:Dome002
 * Package:NetWork
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/7-19:50
 * @Version:v1.0
 */
public class Dome002 {
    /*InetAddress:表示互联网协议IP地址
    * static IneAddress getByName(String host) 确定主机名称的IP地址,主机名称可以是机器名称,也可以是IP名称
    * String getHostName() 获取此IP地址的主机名
    * String getHostAddress() 返回文本显示中的IP地址字符串*/
    public static void main(String[] args) throws UnknownHostException {

        //获取InetAddress的对象
        //IP的对象/一台电脑的对象
        InetAddress address = InetAddress.getByName("DESKTOP-STR201A");//192.168.31.100
        System.out.println(address);

        String hostName = address.getHostName();
        System.out.println(hostName);
        String ip = address.getHostAddress();
        System.out.println(ip);
    }
}
